package communication;

import java.io.IOException;
import java.net.ServerSocket;
import javax.net.ssl.SSLServerSocketFactory;

public class ServerSecureConnectionManager{


	private ServerSocket socket;
		

	public ServerSecureConnectionManager(int port)
	throws ConnectionException{	
		try {
			socket = SSLServerSocketFactory.getDefault().createServerSocket(port);
		} catch (Exception e){
			throw new ConnectionException(e.getMessage());
		}
	}


	public Connection acceptConnection()
	throws ConnectionException{
		try {
            return new ServerSecureConnection(socket.accept());
		} catch (IOException e) {
			throw new ConnectionException(e.getMessage());	
		}
	}


	public void close()
	throws ConnectionException{
		try {
			if(socket!=null){
				socket.close();
				socket = null;
			}
		} catch (IOException e) {
			throw new ConnectionException(e.getMessage());
		}
	}


}
